﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class admintractor_User : System.Web.UI.Page
{
    protected UserBusiness user = new UserBusiness();
    RoleBusiness role = new RoleBusiness();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            binddata();
        }
    }

    public void binddata()
    {
        GridView1.DataSource = user.getUser();
        GridView1.DataBind();
    }
    public string viewRole(int id)
    {
        string tmp = "";
        ArrayList items = role.getRole();
        RoleEntities item = null;
        for (int i = 0; i < items.Count; i++)
        {
            item = (RoleEntities)items[i];
            if (item._id == id)
            {
                tmp = item._name;
                break;
            }
        }
            return tmp;
    }
    public string viewStatus(string status)
    {
        //Response.Write(status);
        if (status.Trim().Equals("True"))
        {
            return "Active";
        }
        else
        {
            return "No active";
        }
    }

    protected void ImEdit_Click(object sender, ImageClickEventArgs e)
    {
        string id = ((ImageButton)sender).CommandArgument.ToString();
        Response.Redirect("UserEdit.aspx?id=" + id);
    }
    protected void ImDelete_Click(object sender, ImageClickEventArgs e)
    {
        string id = ((ImageButton)sender).CommandArgument.ToString();
        //if (!id.Trim().Equals("1"))
        //{
            if (user.delete(int.Parse(id)))
            {
                Response.Redirect("User.aspx");
            }
            else
            {
                lbError.Text = "Xẩy ra nỗi trong quá trình thực hiện";
            }
        //}
        //else
        //{
        //    lbError.Text = "Không xóa được ban ghi này";
        //}

    }
    protected void butadd_Click(object sender, EventArgs e)
    {
        Response.Redirect("UserEdit.aspx");
    }
}
